Repository navigation
D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION: remove post-MEM_RELEASE VA-reuse race in memory_at test - #2939
D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION: remove post-MEM_RELEASE VA-reuse race in memory_at test#2939bobcatchris wants to merge 1 commit into
Conversation
|
Controlled address-reuse check under Wine on With the original Cargo binary basename the stock crash tests passed 19/19 on this PR. The combined crash/profile/stack groups passed 23/23, including #2946’s closed-stderr test. This covers the test behavior under controlled reuse on Wine 11.22. MEASURED with synthetic inputs, OpenAI Codex and a separate read-only review. |
KelboLive
left a comment
There was a problem hiding this comment.
The fix is right, and deletion is the only sound option: after MEM_RELEASE the test has handed the range back to the process, so any post-free VirtualQuery on base is unsound — narrowing the window would not have helped. The low-64 KiB anchor is valid (Windows keeps 0..0x10000 permanently MEM_FREE; I verified memory_at(0) and memory_at(0x1008) both return "nothing mapped there" on Win11 26200), and the PR no longer touches base after the free, so re-reservation cannot bite. crash::tests is 19/19 over 40 runs, and the old assertion is provably wrong: when I reverted it and added a throwaway free-then-VirtualAlloc-same-base probe, memory_at(base + 8) reported "read-write".
Two nits, neither blocking:
memory_at(0x1008)is the sameMEM_FREEregion as the pre-existingmemory_at(0), so it adds no coverage — harmless, just not a second case.- The test now asserts nothing about
MEM_RELEASEactually freeing the range. That is inherently untestable in-process, but worth stating explicitly rather than losing it silently.
Merge is clean against current main, and the textual overlap with #2946 is file-only (hunks are disjoint); #2947 does not touch crash.rs.
VERIFY-2939 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game filesVerdict: PASS. The pull request is right about what is wrong: the assertion it removes does read the address space back as mapped by whoever else happens to allocate, and the replacements it uses read the low addresses that Windows never maps. I reproduced the race rather than trusting the comment. Head 1. What it changesOne test, unsafe { VirtualFree(base as *mut _, 0, MEM_RELEASE) };
- assert_eq!(memory_at(base + 8), "nothing mapped there");
+ // Do not query `base` after `MEM_RELEASE`: concurrent test threads can
+ // immediately reuse the released VA as `PAGE_READWRITE`. Windows keeps
+ // the low 64 KiB (`0..0x10000`) permanently unmapped (`MEM_FREE`).
assert_eq!(memory_at(0), "nothing mapped there");
+ assert_eq!(memory_at(0x1008), "nothing mapped there");
assert_eq!(memory_at(usize::MAX), "outside the address space");Everything is inside the The claim is that after 2. The new test checks the property that mattersThis is a test-only change, so the red side (merge base plus the test hunks) passes the same way the green side does, and the harness cannot show red-then-green. The thing to check instead is whether the old line really races, so I wrote a small standalone program (cross-compiled with the same toolchain and run under Wine) that does the same thing a neighbour test does: it reserves the same range with
So the old line is not deterministic: in roughly one round out of thirty the address space already holds somebody else's The two replacements sit in the low 64 KiB, which is Windows' own null-protection gap. Over the same 200 000 rounds × two addresses the racer had mapped the range thousands of times, and I also checked the new line is live rather than decorative: substituting a value One honest trade-off. The base used this to say something about a range it had just given back, and the pull request no longer says that about the test's own range at all — it leans on the two permanently free addresses instead. That is the right call for a test that must not be flaky, but it does drop coverage: a regression in 3. What the tests do here
Run by hand on the head, the crate's unit suite is 84 passed / 0 failed three times in a row, and 4. Any failure I saw, and why it is not this pull request
The test shells out to 5. What I did not check
The program was scratch work under |
Claimed in the coordination issue as: D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION (#2570 (comment); ref finding #2570 (comment))
What and why
crash::tests::memory_at_names_what_an_access_hit(d3d12/crates/leonida-loader/src/crash.rs:915) calledVirtualFree(base, 0, MEM_RELEASE)and then immediately assertedassert_eq!(memory_at(base + 8), "nothing mapped there").Under parallel
leonida-loadertest runs (including Windows CI), another test thread can reclaim the just-released VA range viaVirtualAlloc(..., PAGE_READWRITE)or the heap allocator beforeVirtualQueryruns, causing intermittent failures (left: "read-write", right: "nothing mapped there").Fix: remove the racy post-
MEM_RELEASEquery onbaseand exerciseMEM_FREEagainst both0and0x1008in Windows' permanently unmapped low-64 KiB guard region (0..0x10000).Tested
cargo test --locked -p leonida-loader --lib crash::tests: 19 passed, 0 failed.python -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/crash.rs: clean.GPUs tested: n/a (CPU/OS virtual-memory query test; Windows 11).
AI-assisted: yes — Gemini 4 Neon (implementation and an independent read-only reviewer pass).
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).